package com.example.jeong.yuejian10.Model;


import com.example.jeong.yuejian10.Bean.AttentionBean;
import com.example.jeong.yuejian10.Bean.IsAttentionBean;
import com.example.jeong.yuejian10.Bean.ProBean;
import com.example.jeong.yuejian10.Listener.RetrofitListener;
import com.example.jeong.yuejian10.Service.ProService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.jeong.yuejian10.constant.Constant.BASE_URL;


public class ProModel {
    private Retrofit retrofit;
    public ProModel(){
        //创建实例
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //大师列表
    public void getProlist(final RetrofitListener listener){
        ProService proService = retrofit.create(ProService.class);
        Call call = proService.getProList();
        Callback<List<ProBean>> callback = new Callback<List<ProBean>>() {
            @Override
            public void onResponse(Call<List<ProBean>> call, Response<List<ProBean>> response) {
                List<ProBean> trainBeen = response.body();
                listener.onSuccess(trainBeen);
            }
            @Override
            public void onFailure(Call<List<ProBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }





    //大师详情
    public Call<ProBean> getProDetail(int pm_id,int pc_id,int ptype_id){
        ProService proService = retrofit.create(ProService.class);
        return proService.getProDetail(pm_id,pc_id,ptype_id);
    }
    //大师课程
    public void getPcList(int pm_id,final RetrofitListener listener){
        ProService proService = retrofit.create(ProService.class);
        Call call = proService.getAllProCourseList(pm_id);
        Callback<List<ProBean>> callback = new Callback<List<ProBean>>() {
            @Override
            public void onResponse(Call<List<ProBean>> call, Response<List<ProBean>> response) {
                List<ProBean> trainBeen = response.body();
                listener.onSuccess(trainBeen);
            }
            @Override
            public void onFailure(Call<List<ProBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }

    //大师课堂详情
    public Call<ProBean> getProfessorCourseDetail(int pm_id,int pc_id) {
        ProService proService = retrofit.create(ProService.class);
        return proService.getPcdetail(pm_id, pc_id);
    }

    //咨询大师列表
    public void consultList(int pm_id,final RetrofitListener listener){
        ProService proService = retrofit.create(ProService.class);
        Call call = proService.getAllConsultList(pm_id);
        Callback<List<ProBean>> callback = new Callback<List<ProBean>>() {
            @Override
            public void onResponse(Call<List<ProBean>> call, Response<List<ProBean>> response) {
                List<ProBean> trainBeen = response.body();
                listener.onSuccess(trainBeen);
            }
            @Override
            public void onFailure(Call<List<ProBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }



    //发表咨询
    public Call<ProBean> consultPro(int pm_id,int u_id,String consultpro){
        ProService proService  = retrofit.create(ProService.class);
        return proService.addConsult(pm_id,u_id,consultpro);
    }

    //判断是否关注
    public Call<IsAttentionBean> getIsCollected(int u_id, int select_id, String flag){
        ProService proService=retrofit.create(ProService.class);
        return proService.getIsCollected(u_id, select_id, flag);
    }

    //关注大师
    public Call<AttentionBean> userCollectPro(int u_id, int pm_id){
        ProService proService=retrofit.create(ProService.class);
        return proService.userCollectPro(u_id,pm_id);
    }


}

